﻿using System;
interface shape
{
    double getArea();
    bool legal();
}
public class retangle:shape
{
    public double x, y;
    public double getArea()  //参数与接口保持一致
    {
        return x*y;
    }
    public bool legal()
    {
        if (x <= 0 && y <= 0 && x == y) { return false; }
        return true;
    }
}
public class triangle : shape
{
    public double x,y,z;
 
    public double getArea()  //参数与接口保持一致
    {
        double p = (x +y + z )/ 2;
        return Math.Sqrt(p*(p-x)*(p-y)*(p-z));  //海伦公式
    }
    public bool legal()
    {
        if (x <= 0 && y <= 0 && z<=0&&x+y<=z&&x+z<=y&&y+z<=x) { return false; }
        return true;
    }
}
public class square : shape
{
    public double x;
    public double getArea()  //参数与接口保持一致
    {
        return x * x;
    }
    public bool legal()
    {
        if (x <= 0) { return false; }
        return true;
    }
    public static void Main(string[] args)
    {
        Console.WriteLine("请选择要创建的图形：1.长方形 2.正方形 3.三角形");
        int n = int.Parse(Console.ReadLine());
        switch (n)
        {
            case 1:
                retangle r=new retangle();
                Console.WriteLine("请输入长方形的长：");
                r.x=int.Parse(Console.ReadLine());
                Console.WriteLine("请输入长方形的宽：");
                r.y=int.Parse(Console.ReadLine());
                Console.WriteLine("面积为:" + r.getArea());
                break;
            case 2:
                square s=new square();
                Console.WriteLine("请输入正方形的边长：");
                s.x = int.Parse(Console.ReadLine());
                Console.WriteLine("面积为:" + s.getArea());
                break;
               
            case 3:
                triangle t = new triangle();
                Console.WriteLine("请输第一条边长：");
                t.x= double.Parse(Console.ReadLine());
                Console.WriteLine("请输第二条边长：");
                t.y = double.Parse(Console.ReadLine());
                Console.WriteLine("请输入第三条边长：");
                t.z = double.Parse(Console.ReadLine());
                Console.WriteLine("面积为:" + t.getArea());
                break;
        }
    }
}